﻿using AutoMapper;
using MediatR;
using S.Breeding.Api.Application.Command.ConditionMeasureCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.ConditionMeasureCommandHandlers
{
    public class ConditionMeasureUpdateCommandHandlers : IRequestHandler<ConditionMeasureUpdateCommand, int>
    {
        private readonly IRepository<ConditionMeasure> repository;
        private readonly IMapper mapper;
        public ConditionMeasureUpdateCommandHandlers(IRepository<ConditionMeasure> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(ConditionMeasureUpdateCommand request, CancellationToken cancellationToken)
        {
            return await repository.UpdateAsync(mapper.Map<ConditionMeasure>(request));
        }
    }
}
